class Solution
{
public:
    bool asteroidsDestroyed(int mass, vector<int> &asteroids)
    {
        sort(asteroids.begin(), asteroids.end());
        long long totalMass = mass;
        int i = 0;
        int n = asteroids.size();
        while (i < n)
        {
            if (totalMass < asteroids[i])
            {
                return false;
            }
            totalMass += asteroids[i];
            ++i;
        }
        return true;
    }
};